#!/usr/bin/env python
# Copyright (C) 2007 by Xyhthyx <xyhthyx@gmail.com>

# This file is part of Parcelle.

# Parcelle is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

# Parcelle is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import pango
import gtk.glade
import common

# Widgets used by control.parcelle
class ParcelleWidgets:
    
	def __init__(self):
		
 		# Set the Glade file
 		self.gladefile = gtk.glade.XML(common.MAIN_GLADE_FILE, common.MAIN_FORM_NAME)
 		
 		# Form widget
 		self.frmMain = self.gladefile.get_widget(common.MAIN_FORM_NAME)
 		
 		# Menu widgets
 		self.mnuOpen = self.gladefile.get_widget('_Open')
 		self.mnuSave = self.gladefile.get_widget('_Save')
 		self.mnuHide = self.gladefile.get_widget('_Hide')
 		self.mnuQuit = self.gladefile.get_widget('_Quit')
 		self.mnuEdit = self.gladefile.get_widget('_Edit')
 		self.mnuCopy = self.gladefile.get_widget('_Copy')
 		self.mnuDelete = self.gladefile.get_widget('_Delete')
 		self.mnuClear = self.gladefile.get_widget('_Clear')
 		self.mnuPreferences = self.gladefile.get_widget('_Preferences')
 		self.mnuAbout = self.gladefile.get_widget('_About')
 		
 		# Toolbar button widgets
 		self.btnPreferences = self.gladefile.get_widget('ToolPreferences')
 		self.btnOpen = self.gladefile.get_widget('ToolOpen')
 		self.btnSave = self.gladefile.get_widget('ToolSave')
 		self.btnEdit = self.gladefile.get_widget('ToolEdit')
 		self.btnCopy = self.gladefile.get_widget('ToolCopy')
 		self.btnDelete = self.gladefile.get_widget('ToolDelete')
 		self.btnClear = self.gladefile.get_widget('ToolClear')
 		self.btnHide = self.gladefile.get_widget('ToolHide')
 		self.btnQuit = self.gladefile.get_widget('ToolQuit')
 		
 		# Notebook button widgets
 		self.btnClipboardSave = self.gladefile.get_widget('clipSave')
 		self.btnClipboardBack = self.gladefile.get_widget('clipBack')
 		self.btnEditSave = self.gladefile.get_widget('editSave')
 		self.btnEditCancel = self.gladefile.get_widget('editCancel')
 		
 		# Treeview and notebook widgets
 		self.trParcelle = self.gladefile.get_widget('Treeview')
 		self.notebook = self.gladefile.get_widget('Notebook')
 		
 		# View and search widgets
 		self.tglItems = self.gladefile.get_widget('ItemsToggle')
 		self.tglClipboard = self.gladefile.get_widget('ClipboardToggle')
 		self.entFind = self.gladefile.get_widget('FindEntry')
 		self.btnFind = self.gladefile.get_widget('FindButton')
 		self.btnFindClear = self.gladefile.get_widget('FindClearButton')
 		
 		# Textview widgets
 		self.lblClipboard = self.gladefile.get_widget('EditingClipboardLabel')
 		self.lblCount = self.gladefile.get_widget('CountLabel')
 		self.txtClipboard = self.gladefile.get_widget('clipTextview')
 		self.txtEdit = self.gladefile.get_widget('editTextview')
 		
		# -------------------------------
		#  Add keyboard accelerators
		# -------------------------------
		accel_group = gtk.AccelGroup()
		self.frmMain.add_accel_group(accel_group)
		self.mnuSave.add_accelerator('activate', accel_group, ord('S'), gtk.gdk.SHIFT_MASK | gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
		self.mnuEdit.add_accelerator('activate', accel_group, ord('E'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
		self.mnuDelete.add_accelerator('activate', accel_group, 65535, gtk.gdk.RELEASE_MASK, gtk.ACCEL_VISIBLE)
		self.btnClipboardSave.add_accelerator('activate', accel_group, ord('S'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
		self.btnEditSave.add_accelerator('activate', accel_group, ord('S'), gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
		
		# -------------------------------
		#  Make modifications to widgets
		# -------------------------------
		
		# Fix toolbar icon size and set window icon
		self.gladefile.get_widget('Toolbar').set_style(gtk.TOOLBAR_ICONS)
		icon = self.frmMain.render_icon(gtk.STOCK_PASTE, gtk.ICON_SIZE_MENU)
		self.frmMain.set_icon(icon)
		
		# Fix hide menu item icon
		menu_image = gtk.Image()
		menu_image.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_MENU)
		self.mnuHide.set_image(menu_image)
		
		# Build treeview columns
		tree_column = gtk.TreeViewColumn('Date Modified', gtk.CellRendererText(), text=0)
		tree_column.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY)
		tree_column.set_alignment(0.5)
		tree_column.set_sort_column_id(0)
		self.trParcelle.append_column(tree_column)
		cell_renderer = gtk.CellRendererText()
		cell_renderer.set_property('ellipsize-set', True)
		cell_renderer.set_property('ellipsize', pango.ELLIPSIZE_END)
		tree_column = gtk.TreeViewColumn('Item', cell_renderer, text=1)
		tree_column.set_expand(True)
		tree_column.set_alignment(0.5)
		tree_column.set_sort_column_id(1)
		self.trParcelle.append_column(tree_column)
